
import pandas as pd 
import numpy as np
import time
import cx_Oracle
from sqlalchemy import create_engine



#动态获取数据库参数
def get_params(db_flag):
    if db_flag == 'test':
        host = '22.208.119.140'
        port = '1521'
        databases = 'miskf'
        user = 'esg2_user'
        password = 'esg0101'
    else:
        host = '22.208.119.140'
        port = '1521'
        databases = 'miskf'
        user = 'esg_user'
        password = 'esg0101'
    return host,port,databases,user,password


#判断日跑批还是月跑批
def which_id(id_mark):                           #传入　：id_mark 为列表　　返回：sql的索引
    evalate_id = '(' + str(id_mark)[1:-1] + ')'        # 解析id_mark
    if 'ESG_DATA' in evalate_id:               
        index_id = 'BATCH_ID'
        batch_flag = 1
    else:
        index_id  = 'RATING_ID'                  #考虑将batch_flag 与之结合 跑批才加batch_id
        batch_flag = 0
    return index_id,evalate_id,batch_flag                   #判断利用哪种索引为id为后续数据删除或者提取提供依据
 

#获取batch_id内容 
def get_batch_id(dfjch,batch_flag):
    if batch_flag == 1:                                                           #如果是跑批次则获取批次id 
        batch_id = dfjch.batch_id.values[0]
    #elif 'ESG' in dfjch.batch_id.values[0]:
        #batch_id = dfjch.batch_id.values[0]
    else:
        batch_id = None
    return batch_id
